<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html>
<head>
<%@ include file="common.jsp"%>

<link type="text/css" rel="stylesheet"
	href="<%=rootPath%>/css/manage/selectResult.css" />
<title><%=proName%>-日志权限</title>
<script type="text/javascript">
	//初始化权限类别描述
	var powerTypeDesc = {
			NC_CanViewUser:"可以查看他人日志的",
			NC_CanReviewUser:"可以审阅他人日志的",
			NC_CanBeReviewUser:"可以被审阅的",
			HO_CanViewUser:"总公司员工可以查看分公司日志的",
			HO_CanReviewUser:"总公司员工可以评论分公司日志的",
			HO_CanShareUser:"可以分享他人日志的用户",
			desc : function(type){
				if(type == "NC_CanViewUser"){
					return this.NC_CanViewUser;
				}else if(type == "NC_CanReviewUser"){
					return this.NC_CanReviewUser;
				}else if(type == "NC_CanBeReviewUser"){
					return this.NC_CanBeReviewUser;
				}else if(type == "HO_CanViewUser"){
					return this.HO_CanViewUser;
				}else if(type == "HO_CanReviewUser"){
					return this.HO_CanReviewUser;
				}else if(type == "HO_CanShareUser"){
					return this.HO_CanShareUser;
				}
			}
	};
	//添加员工编号输入框
	function addEmpId(){
		var row = 0;
		$("#addTable tr[id]").each(function(i){
			var trid = this.id;
			trid = trid.substr(trid.lastIndexOf("_")+1);
			if(parseInt(trid) >= row){
				row = parseInt(trid) + 1;
			}
		});
		var html = "";
		html += '<tr id="emp_' + row + '" style="background-color: #F7F4D8;border-bottom: 1px solid gray;">';
		html += '<td align="center"><input id="empId_' + row + '" type="text" name="empIds" /></td>';
		html += '<td align="left"><a href="javascript:deleteEmpRow(\'emp_' + row + '\')">删除</a></td>';
		html += '</tr>';
		$("#addTable").append(html);
	}
      //删除一条员工编号输入框
	function deleteEmpRow(emp_row){
		var row = 0;
		$("#addTable tr[id]").each(function(i){
				row++ ;
		});
		if(row > 1){
   			$("#"+emp_row).remove();
		}
	}
    //保存已添加员工号
	function saveEmp(){
		var powerType = $("#powerType").val();
		var url = saveForm.action;
		if(confirm('是否确认保存这些员工拥有  "'+powerTypeDesc.desc(powerType) +'"  的权限？')){
			$.ajax({
    		  	url: url,
    		  	type: "POST",
    		  	data:$("#saveForm").serialize(),
    		  	dataType: "text",
    		  	success: function( response ) {
    		  		var data=$.parseJSON(response);
    				if(data.state=="200"){
    					if(data.data == "" || data.data == null || data.data == "null"){
    						location.href = "<%=rootPath%>/workConPower/findEmpListByPowerType.mge?powerType="+powerType;
    					}else{
    						showToast(false,data.msg);
    						$("#addTable tr[id]").each(function(i){
    							var trid = this.id;
    							var index = trid.substr(trid.lastIndexOf("_")+1);
    							var empId = $("#empId_"+index).val();
    							var notExistEmp = data.data;
    							if(notExistEmp.indexOf(empId) == -1){
    								$("#"+trid).remove();
    							}
    						});
    					}
    				}else{
    					showToast(false,data.msg);
    				}
    		  	}
    		});
		}
	}
    //查询权限员工列表
    function searchEmp(){
    	var powerType = $("#powerType").val();
    	location.href = "<%=rootPath%>/workConPower/findEmpListByPowerType.mge?powerType=" + powerType;
	}
</script>
</head>

<body>
	<jsp:include page="./menu.jsp"></jsp:include>
	<div id="body">
		<div id="navTop">
			<div class="bg_left"></div>
			<div class="bg_main"></div>
			<div class="bg_right"></div>
		</div>
		<div id="userManager">
			<form id="saveForm" method="post" name="saveForm" action="<%=rootPath%>/workConPower/save.mge" title=''>
				<table width="100%" cellpadding="0" cellspacing="0" border="0"
					class="maintable">
					<tr>
						<th align="left" valign="middle">
							<table cellpadding="0" cellspacing="0">
								<tr>
									<th><span id="search_icon" class="search_icon"></span></th>
									<th height="30px"><span style="margin-left: 2px;">权限选择</span></th>
								</tr>
							</table>
						</th>
					</tr>
					<tr>
						<td>
							<table width="100%" cellpadding="0" cellspacing="0" border="0">
								<tr>
									<td colspan="2" align="left">
										<table cellpadding="0" cellspacing="0" border="0">
											<tr>
												<td width="100px" bgcolor="#DDDDDD"><span>权限类型：</span></td>
												<td width="5px"></td>
												<td>
													<select id="powerType" name="powerType" style="width: 182px">
														<option value="NC_CanViewUser" <c:if test="${powerType=='NC_CanViewUser'}">selected</c:if>>可以查看他人日志的用户</option>
														<option value="NC_CanReviewUser" <c:if test="${powerType=='NC_CanReviewUser'}">selected</c:if>>可以审阅他人日志的用户</option>
														<option value="NC_CanBeReviewUser" <c:if test="${powerType=='NC_CanBeReviewUser'}">selected</c:if>>可以被审阅的用户</option>
														<option value="HO_CanViewUser" <c:if test="${powerType=='HO_CanViewUser'}">selected</c:if>>总公司员工可以查看分公司日志的用户</option>
														<option value="HO_CanReviewUser" <c:if test="${powerType=='HO_CanReviewUser'}">selected</c:if>>总公司员工可以评论分公司日志的用户</option>
														<option value="HO_CanShareUser" <c:if test="${powerType=='HO_CanShareUser'}">selected</c:if>>可以分享他人日志的用户</option>
													</select>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<th align="right">
										<input id="search" type="button" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" value="查    询" onclick="searchEmp()" onmouseover="this.style.background='#FFF18B'" onmouseout="this.style.background='#F1EDD2'" />
										<input id="save" type="button" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" value="保    存" onclick="saveEmp()" onmouseover="this.style.background='#FFF18B'" onmouseout="this.style.background='#F1EDD2'" />
									</th>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td align="left">
							<table cellpadding="0" cellspacing="0" border="0">
								<tr>
									<th><span id="search_icon1" class="search_icon"></span></th>
									<th height="30px"><span style="margin-left: 2px;">添加工号</span></th>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table id="addTable" class="admintable" width="100%"
								style="margin: auto">
								<tr>
									<th colspan="2" class="adminth">
										<input id="add" type="button" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" value="添    加" onclick="addEmpId()" onmouseover="this.style.background='#FFF18B'" onmouseout="this.style.background='#F1EDD2'" />
									</th>
								</tr>
								<tr id="emp_1" style="background-color: #F7F4D8; border-bottom: 1px solid gray;">
									<td align="center"><input id="empId_1" type="text" name="empIds" /></td>
									<td><a href="javascript:deleteEmpRow('emp_1')">删除</a></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<jsp:include page="./footer.jsp"></jsp:include>
</body>
</html>
